public class Main {
    public int removeElement(int[] nums, int val) {
        int left=0;
        int right=nums.length-1;
        while(left<=right){
            if(nums[left]==val){
                nums[left]=nums[right];
                right--;
            }else{
                left++;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,2,3,3,4};
        Main m = new Main();

        int ret=m.removeElement(nums,3);
        for(int i=0;i<ret;i++){
            System.out.print(nums[i]+" ");
        }

    }
}
